/*
 *  ocultar_notas_request.cpp
 *  Wilson
 *
 *  Created by Sebastian Orfino on 1/17/12.
 *  Copyright 2012 lbs3. All rights reserved.
 *
 */
#include "VCPlugInHeaders.h"



//stl includes


//sdk includes
#include "IDocument.h"
#include "ErrorUtils.h"
#include "Utils.h"
#include "ISpreadList.h"
#include "ILayoutUIUtils.h"

//project includes
#include "marcadores.h"
#include "pugixml.hpp"
//#include "mi_layer.h"

#include "ocultar_notas_request.h"

using namespace std;
using namespace eventos;

void ocultar_notas_request::operator()(const csxs::event::Event * const eventParam)
{
	using namespace pugi;
	IDocument * frontDoc = Utils<ILayoutUIUtils>()->GetFrontDocument();
	if (!frontDoc) return;
	
	payload_ = eventParam->data;
	
	xml_document docu;
	xml_parse_result result = docu.load(eventParam->data);
	
	if (!result) {
		PMString msg(result.description());
		msg.SetTranslatable(kFalse);
		ErrorUtils::PMSetGlobalErrorCode((ErrorCode)result.status,&msg);
		return;
	}
	
	string siNo = docu.child("payload").child("ocultar").child_value();
	if (!siNo.length()) return;
	std::istringstream is(siNo);
	bool ocultar;
	is >> boolalpha >> ocultar;
	
	doc::marcadores doc(::GetUIDRef(frontDoc));
	doc.visibilidad(!ocultar);
	
/*	InterfacePtr<ISpreadList> spread_list(frontDoc,UseDefaultIID());
	if (!spread_list) return;
	
	//NOTA: fijarse que mi_layer siempre crea WILSON_NOT_PRINTABLE cuando se lo instancia sobre un spread, por mas que ese 
	//spread no tenga notas pegadas. Esto igual es inofensivo.
	for (int32 i = 0; i< spread_list->GetSpreadCount();++i) {
	
		UID spread_uid = spread_list->GetNthSpreadUID(i);
		UIDRef spread_ref(::GetDataBase(frontDoc),spread_uid);
		wilson::mi_layer layer(spread_ref);
		if (ocultar) layer.ocultar();
		else layer.mostrar();
	
	}
	*/
	
	
}